import {Component, EventEmitter, Input, Output} from '@angular/core';
import {Form} from "../api/Form";
import {FormDirective} from "./form.directive";

@Component({
  selector: 'gn-form-button',
  template: `
    <div class="formConfirm">
      <button pButton type="button" label="保存" icon="pi pi-check"
              class="ui-button-raised ui-button-success" [disabled]="form.formGroup.invalid"
              (click)="click()"></button>
    </div>
  `
})
export class FormButtonComponent {

  @Output() onClick = new EventEmitter();

  constructor(public form: FormDirective) {
  }

  click(): void {
    if (this.onClick.observers.length > 0) {
      this.onClick.emit();
    } else {
      this.form.submit();
    }
  }

}
